<?
//print_r($this->user);
//echo $this->role;
//
if($this->acl->isAllowed($this->role,'product','view')){
	//echo "yes";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Plima</title>
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl?>/public/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl?>/public/css/icons.css" /> 
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ext-base.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ext-all.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/XmlTreeLoader.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/menu/RangeMenu.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/menu/EditableItem.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/GridFilters.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/Filter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/StringFilter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/DateFilter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/ListFilter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/NumericFilter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/filter/BooleanFilter.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/lightbox.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/RowExpander.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ben/showresult.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ux/DDView.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ux/ItemSelector.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ux/MultiSelect.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ux/GroupSummary.js"></script>
<script type="text/javascript" src="<?=$this->baseUrl?>/public/js/ux/FileUploadField.js"></script>
</head>
<style type="text/css">

#loading {
	position:absolute;
	left:45%;
	top:40%;
	padding:2px;
	z-index:20001;
	height:auto;
}
#loading a {
	color:#225588;
}
#loading .loading-indicator {
	background:white;
	color:#444;
	font:bold 13px tahoma, arial, helvetica;
	padding:10px;
	width:200px;
	margin:0;
	height:auto;
}
#loading-msg {
	font: normal 10px arial, tahoma, sans-serif;
}

</style>
<script type="text/javascript">
 
var today="<?=date('Y-m-d')?>";
//var today="2010-05-02";
var Tree = Ext.tree;
var detailsText = '<b>please select a order</b>';
//读取xml
Ext.app.MenuLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
    processAttributes : function(attr){
        if(attr.name){ // is it an author node?
            // Set the node text that will show in the tree since our raw data does not include a text attribute:
            attr.text = attr.name;  
            // Author icon, using the gender flag to choose a specific icon:
            // Override these values for our folder nodes because we are loading all data at once.  If we were
            // loading each node asynchronously (the default) we would not want to do this:
            attr.loaded = true;
            //attr.expanded = true;
        }
        else if(attr.title){ // is it a book node?
            
            // Set the node text that will show in the tree since our raw data does not include a text attribute:
            attr.text = attr.title ;       
            // Tell the tree this is a leaf node.  This could also be passed as an attribute in the original XML,
            // but this example demonstrates that you can control this even when you cannot dictate the format of 
            // the incoming source XML:
            attr.leaf = true;
        }
    }
});
//显示模板
var tpl = new Ext.Template(
       '<p><b>title:</b>: {title}</p>',
        '<p><b>codeby</b>: {editby}</p>',
        '<p><b>链接</b><a href="{url}" target="_blank">{url}</a></p>',
		'<p><b>内容</b>:{content}</p>'
	);
    tpl.compile();


Ext.state.Manager.setProvider(new Ext.state.CookieProvider());	
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';	

/*页面初始化*/
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL = '<?=$this->baseUrl?>/public/images/default/s.gif';


//定义初始化					 

setTimeout(function() {
		Ext.get('loading').fadeOut({
			remove : true
		});
	}, 250);
//左边菜单
var MenuTree=new Ext.Panel({		
		region:'west',
		split:true,
        title: '菜单',
        layout: 'accordion',
	    width: 200,
		minSize:100,
		maxSize:300,
		collapsible:true,
		layoutConfig:{
                    animate:true
                },
        items: [{
			title:'网站产品',
			collapsed:true, 
			iconCls:'icn-views-detail',
            xtype: 'treepanel',
            id: 'tree-panel_base',
            margins: '2 2 0 2',
            autoScroll: true,
	        rootVisible: false,
			border:false,
	        root: new Ext.tree.AsyncTreeNode(),            
	        loader: new Ext.app.MenuLoader({
	            dataUrl:'<?=$this->baseUrl?>/index/menuproduct'
	        }),            
	        listeners: {
	            'render': tree_click
	        }
        }
		<?php if($this->acl->isAllowed($this->role,'order','menumain')) {?>
		,
		{
			title:'网站订单',
			collapsed:true,
			iconCls:'icn-user-chart',
            xtype: 'treepanel',
            id: 'tree-panel_order',
            margins: '2 2 0 2',
            autoScroll: true,
	        rootVisible: false,
			border:false,
	        root: new Ext.tree.AsyncTreeNode(),            
	        loader: new Ext.app.MenuLoader({
	            dataUrl:'<?=$this->baseUrl?>/index/menuorder'
	        }),            
	        listeners: {
	            'render': tree_click
	        }
        }
		<?php } ?>
		<?php if($this->acl->isAllowed($this->role,'order','menumain')) {?>
		,
		{
			title:'链接管理系统',
			iconCls:'icn-key',
            xtype: 'treepanel',
            id: 'tree-panel_link',
            margins: '2 2 0 2',
            autoScroll: true,
	        rootVisible: false,
			border:false,
	        root: new Ext.tree.AsyncTreeNode(),            
	        loader: new Ext.app.MenuLoader({
	            dataUrl:'<?=$this->baseUrl?>/index/menulink'
	        }),            
	        listeners: {
	            'render': tree_click
	        },
			bbar:[
				  {text:"数据统计",iconCls:'icn-chart',handler:function(){
					  window.open('/link/chart');
					  }}]
        }
		<?php } ?>
		<?php if($this->acl->isAllowed($this->role,'admin','menumain')) {?>
		,{
            title: '管理员',
			iconCls:'icn-group',
            id: 'tree-panel_admin',
			xtype: 'treepanel',
            margins: '2 2 0 2',
            autoScroll: true,
	        rootVisible: false,
			border:false,
	        root: new Ext.tree.AsyncTreeNode(),            
	        loader: new Ext.app.MenuLoader({
	            dataUrl:'<?=$this->baseUrl?>/index/menuadmin'
	        }),            
	        listeners: {
	            'render': tree_click
	        }
        }
		<?php } ?>
		]
});

//主体内容
var content=new Ext.TabPanel({
									id:'content',
									title:'主题内容',									
									region:'center',
									resizeTabs:true, 
        							minTabWidth: 115,
        							tabWidth:135,
        							enableTabScroll:true,        							
									autoDestroy:true,
									deferredRender:false,
									layoutOnTabChange:true,
									autoLoad:false,
                    				activeTab:0,									
									items:[{   
												id:'first',
                        						title:'欢迎你',                        					
                        						autoScroll:true,
												iconCls:'icn-world',
                        						//html:'hello world'
                        						html : '<iframe frameborder="0" width="100%" height="100%" src="<?=$this->baseUrl?>/index/welcome"></iframe>'
											//autoLoad:{url:'<?=$this->baseUrl?>/index/welcome',scripts:true,nocache:true}
                    						}/*,
											{   
												id:'second',
                        						title:'图表测试',                        					
                        						autoScroll:true,
												iconCls:'icn-world',
                        						html : '<iframe frameborder="0" width="100%" height="100%" src="<?=$this->baseUrl?>/index/charts"></iframe>'
											//autoLoad:{url:'<?=$this->baseUrl?>/index/welcome',scripts:true,nocache:true}
                    						}*/]															
});
//右边菜单
var menuRight=new Ext.TabPanel({
									title:'菜单',									
									region:'east',
									width:100,
									collapsible:true,
									animate: true,
									closeOnTab:true,
									closable: true
});
//上面布局
var tb = new Ext.Toolbar({
						 region:'north'
						 });
tb.render('toolbar');
tb.add({
            text:'菜单',
            iconCls: 'icn-menu',
			menu:{
				items:[	
					   {
						   text:'8001',
						   href:'http://192.168.1.20:8001',
						   hrefTarget:'_blank'
						},
						{
						   text:'8002',
						   href:'http://192.168.1.20:8002',
						   hrefTarget:'_blank'
						},
						{
						   text:'8003',
						   href:'http://192.168.1.20:8003',
						   hrefTarget:'_blank'
						},
						{
						   text:'8003',
						   href:'http://192.168.1.20:8003',
						   hrefTarget:'_blank'
						},
						{
						   text:'8004',
						   href:'http://192.168.1.20:8004',
						   hrefTarget:'_blank'
						},
						{
						   text:'8005',
						   href:'http://192.168.1.20:8005',
						   hrefTarget:'_blank'
						},'-',
						{
						   text:'修改密码',
						   handler:changePwd   
						},'-',				   
					   {text:'退出',
					   	handler:function(){location.href='logout';}}						
					   ]
				}
        }, 
        new Ext.Button({
            text: '线上站点',
            tooltip: {text:'快速访问线上站点', title:'提示'},
            iconCls: 'blist',
            // Menus can be built/referenced by using nested menu config objects
            menu : {items: [
                        {text: '8001：luxcellphone.com',href:'http://www.luxcellphone.com',hrefTarget:'_blank'},
                        {text: '8002：myluxphone.com',href:'http://www.myluxphone.com',hrefTarget:'_blank'},
						{text: '8003：myreplicaphone.com',href:'http://www.myreplicaphone.com',hrefTarget:'_blank'},
						{text: '8004：luxphoneworld.com',href:'http://www.luxphoneworld.com',hrefTarget:'_blank'},
						{text: '8005：handbagseshop.com',href:'http://www.handbagseshop.com',hrefTarget:'_blank'}
                ]}
        }),{xtype:'tbfill'},new Ext.ux.ThemeCycleButton);

//底部状态栏
var foot = new Ext.StatusBar({
        region: 'south',
				cls:'foot',
				statusAlign: 'right',
				items : ['　', '<?php echo date('Y-m-d l h:i'); ?>','-','user:<?=$this->user['username']?>','-','website：<a href="http://www.plima.cn/" target="_blank">http://www.plima.cn/</a>','->','Editor：ben', '-', new Ext.Toolbar.TextItem({id:'app_version',text:' '})],
				listeners:{
					render:function(){
						Ext.Ajax.request({
							url:"<?=$this->baseUrl?>/log.txt",
							success: function(res, op){
								var v = res.responseText;
								v = v.substr(0,v.indexOf(' '));
								this.items.items[7].getEl().innerHTML = '当前版本：'+v;
							},
							scope:this
						});
					}
				}
		});
//主体布局
	var view=new Ext.Viewport({
						 enableTabScroll:true,
						 layout:'border',
						 items:[tb,content,MenuTree,foot]			 
	});

	
	//var details = Ext.getCmp('details-panel').body;
	Ext.getCmp("tree-panel_base").expandAll(); 
	<?php if($this->acl->isAllowed($this->role,'order','menumain')) {?>	
	Ext.getCmp("tree-panel_order").expandAll();
	<?php } ?>
	<?php if($this->acl->isAllowed($this->role,'admin','menumain')) {?>	
	Ext.getCmp("tree-panel_link").expandAll();
	<?php } ?>
	<?php if($this->acl->isAllowed($this->role,'admin','menumain')) {?>	
	Ext.getCmp("tree-panel_admin").expandAll();
	<?php } ?>



//tab上右键菜单

content.addListener('contextMenu',tabsRightMenu);
function tabsRightMenu(tabs,myitem,e){
e.preventDefault();
var contextMenu=new Ext.menu.Menu([
    								{
    									text:"关闭当前页",
										iconCls:'icn-remove',
    									handler:function(){	
										if(myitem.closable){
											content.remove(myitem);	
											}									
											return;
										}
    								},{
										text:'刷新',
										iconCls:'icn-refresh',
										handler:function(){											
											myitem.getUpdater().refresh();
											}
										},{
    									text:"关闭其他所有页",
										iconCls:'icn-publish-remove',
    									handler:function(){
    									//循环遍历
    									content.items.each(function(item){
        									if(item.closable&&item!=myitem){
                 						//可以关闭的其他所有标签页全部关掉
                    							content.remove(item);
                						}
       	 						   });
    								}
    								}
    								]);
contextMenu.showAt(e.getXY());
}


/*辅助函数及响应事件函数<?echo WEB_URL;?>*/
//左边菜单点击
function tree_click(tp){
                    tp.getSelectionModel().on('selectionchange', function(tree, node){
	                    if(node.leaf){
//alert(node.attributes.title+"|url="+node.attributes.url+"/id/"+node.attributes.id+"|id="+node.attributes.nodeId);
							addtab(node.attributes.title+" "+node.attributes.siteId,"<?=WEB_URL?>"+node.attributes.url+"/id/"+node.attributes.siteId,node.attributes.id);						//openWindow("test"+Math.random(),node.attributes.title,node.attributes.url,900,520);
	                    }else{
                           //details.update(detailsText);
                        }
                    })
}

function addtab(name,link,id){
	var main=Ext.getCmp('content');
	var tabId="tab_"+id;
	var tabLink=link;
	var tabTitle=name;
	var tab=main.getComponent(tabId);
	var subMainId='tab_'+id+'main';
    if(!tab){
        tab=main.add({
				'id':tabId,
				'title':tabTitle,
				closable:true,
				autoScroll : true ,
				layout : 'fit' ,
				border : false
				//autoLoad:{url:tabLink,scripts:true,nocache:true}
				});        
		main.setActiveTab(tab);  
		var loadmask = new Ext.LoadMask(tab.body,{msg:"页面加载中……"}) ;		
		loadmask.show() ;
		tab.load({
			url: tabLink,
			discardUrl: false,
			//nocache: true,
			timeout: 3000,
			scripts: true,
			text:'',
			callback:function(a,b,c){
				if(b){
					loadmask.hide();
					}
				}
		});
    }
	main.setActiveTab(tab);    
}

//关闭所有标签
function item_close_all(){
	Ext.getCmp('content').items.each(function(item){
		if(item.closable){
			Ext.getCmp('content').remove(item);
        }
    });
}
//打开一个窗口
function openWindow(id,title,url,width,height){
	var win = Ext.get(id);
	if (win) {
		win.show();
		return;
	}
	win = new Ext.Window({
		id:id,
		title:title,
		layout:'fit',
		width:width,
		height:height,
		closeAction:'close',
		collapsible:true,
		plain: true,
		html : '<iframe frameborder="0" width="100%" height="100%" src="'+url+'"></iframe>'
	});
	win.show();
}

function changePwd(){
	var form_edit=new Ext.FormPanel({								   
		labelAlign:'top',
		frame:true,
		plain:true,
		id:'user_add',
		buttonAlign : 'center',  
		bodyStyle:'padding:5px',
		width:600,
		items:[{
			   layout:'column',
			   border:false,
			   items:[{
			   		columnWidth:.5,
					layout:'form',
					border:false,
					items:[{
						   xtype:'textfield',
						   fieldLabel:'realname',
						   name:'realname',
						   value:'<?=$this->user['realname']?>',
						   anchor:'80%',
						   allowBlank:false
						   },
						   {
							xtype:'hidden',
							name:'id',
							value:'<?=$this->user['u_id']?>'
							},
							{
							xtype:'hidden',
							name:'role',
							value:'<?=$this->user['role']?>'
							},
						   {
						   xtype:'textfield',
						   fieldLabel:'password',
						   name:'pwd1',
						   inputType : 'password',
						   anchor:'80%',
						   allowBlank:false
						   },
						   {
						   xtype:'textfield',
						   fieldLabel:'Email',
						   name:'email',
						   value:'<?=$this->user['email']?>',
						   anchor:'80%',
						   allowBlank:false,
						   vtype:'email'
						   }]
					  },
					  {
			   		columnWidth:.5,
					layout:'form',
					border:false,
					items:[{
						   xtype:'textfield',
						   fieldLabel:'username',
						   name:'username',
						   anchor:'80%',
						   value:'<?=$this->user['username']?>',
						   readOnly:true,
						   disable:true,
						   allowBlank:false
						   },
						   {
						   xtype:'textfield',
						   fieldLabel:'repeat password',
						   name:'pwd2',
						   inputType : 'password',
						   anchor:'80%'
						   }]
					  }]			   
			   }],
		buttons:[{
				 text:'save',
				 name:'submit',
				 id:'save',
				 handler:function(){
					 if(form_edit.getForm().isValid()){
					 form_edit.getForm().submit({
							waitTitle: '提示',
							waitMsg:'等待中',
							url:'<?=$this->baseUrl?>/user/add',
							method:'post',
							success:function(form,action){
								var temp=Ext.util.JSON.decode(action.response.responseText);
								Ext.MessageBox.alert('成功',temp.msg);
								win_user_add.hide();
								},
							failure:function(form,action){
								var temp=Ext.util.JSON.decode(action.response.responseText);
								Ext.MessageBox.alert('waring',temp.msg);
								}
							});
					 }}
				 },
				 {
				text:'cancel',	 
				name:'cancel',
				id:'cancel',
				handler:function(){
					win_user_add.hide();
					}
				}]
	});
var win_user_add=new Ext.Window({
								 				resizable	: true,
												width		: 550,	
												title		: '用户管理',
												autoHeight	: true,
												items		: [form_edit],
												buttonAlign	: 'center',
												listeners	: {"close":function(){
													//alert("关闭");
													//win_user_add.hide();													
													}}
													});
win_user_add.show();
	
}


//任务自动加载进行
setTimeout(function(){
//Ext.Ajax.request({
//				 url:"<?=$this->baseUrl?>/link/auto"
//				 });
},100000);

});
</script>
<body>
<div id="toolbar"></div>
<div id="loading">
  <div><img src="<?=$this->baseUrl?>/public/images/logo.gif" width="32" height="32" style="margin-right:8px;float:left;vertical-align:top;"/>Plima system<br />
    <span id="loading-msg">Loading...</span></div>
</div>
</body>
</html>
